﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AdornerTest
{
    /// <summary>
    /// IPTMediaPlay.xaml 的交互逻辑
    /// </summary>
    public partial class IPTMediaPlay : UserControl
    {
        private int _playStatus;
        private string _mediaFileName;

        public int PlayStatus { get; set; }
        public string MediaFileName { get; set; }

        public IPTMediaPlay()
        {
            InitializeComponent();
        }

        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            mediaPlayerMain.Play();
            mediaPlayerMain.Volume = (double)sliderVolume.Value;
        }

        private void btnPause_Click(object sender, RoutedEventArgs e)
        {
            mediaPlayerMain.Pause();
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            mediaPlayerMain.Stop();
        }

        /// <summary>
        /// seek mediao to Position(x)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SeekToMediaPosition(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            int SliderValue = (int)sliderTime.Value;
            TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
            mediaPlayerMain.Position = ts;
        }

        /// <summary>
        /// 调节声音大小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChangeMediaVolume(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            mediaPlayerMain.Volume = (double)sliderVolume.Value;
        }

        /// <summary>
        /// 播放结束
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mediaPlayerMain_MediaEnded(object sender, RoutedEventArgs e)
        {
            mediaPlayerMain.Stop();
        }
    }
}
